package com.day03;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
public class XMLprovider extends AbstactProvider{
    private File file;
    public XMLprovider(File file){
    	this.file=file;
    }
	@Override
	public List<Person> getPeopleList() {
		SAXBuilder build=new SAXBuilder();
		List<Person> list=new ArrayList<Person>();
		// TODO Auto-generated method stub
		try {
			Document doc =build.build(file);
			Element e=doc.getRootElement();
			List<Element>ls=e.getChildren();
			for(Element element : ls){
				Person p =new Person();
				p.setFirstName(element.getChildText("firstName"));
				p.setLastName(element.getChildText("lastName"));
				p.setCompanyName(element.getChildText("companyName"));
				p.setAddress(element.getChildText("address"));
				p.setCity(element.getChildText("city"));
				p.setCounty(element.getChildText("county"));
				p.setPostal(element.getChildText("postal"));
				p.setPhone1(element.getChildText("phone1"));
				p.setPhone2(element.getChildText("phone2"));
				p.setEmail(element.getChildText("email"));
				p.setWeb(element.getChildText("web"));
				list.add(p);
			}		
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

}
